package main

import (
	"fmt"
	"strconv"
	"sync"
	"time"
)

// 测试读写锁

func main() {
	var rwLock sync.RWMutex
	var ch = make(chan struct{}, 10)
	count := 10
	for i := 0; i < count; i++ {
		go func(i int) {
			rwLock.Lock()
			// rwLock.RLock()
			fmt.Print("go线程" + strconv.Itoa(i))
			time.Sleep(time.Second * 1)
			fmt.Print("go线程" + strconv.Itoa(i) + "结束")
			defer rwLock.Unlock()
			// defer rwLock.RUnlock()
			ch <- struct{}{}
		}(i)
	}

	for i := 0; i < count; i++ {
		<-ch
	}
}
